package net.bithappens.hnqe.scratchpad;

import java.net.URI;

import net.bithappens.hnqe.graph.GraphNode;
import net.bithappens.hnqe.graph.GraphRelation;
import net.bithappens.hnqe.graph.GraphRelationMember;
import net.bithappens.hnqe.impl.rest.provider.GraphRelationMemberJsonAddapter;
import net.bithappens.hnqe.query.Constraint;
import net.bithappens.hnqe.query.ConstraintMath;
import net.bithappens.hnqe.query.ConstraintMath.MathOperation;
import net.bithappens.hnqe.query.Link;
import net.bithappens.hnqe.query.Node;
import net.bithappens.hnqe.query.QueryFactory;
import net.bithappens.hnqe.query.QueryTree;
import net.bithappens.hnqe.query.Relation;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

public class TestGson {

	public static void main(String[] args) throws Exception {
		
		QueryFactory factory = new QueryFactory();
		
		Node bob = factory.newNode("person");
		Node alice = factory.newNode("person");
		
		Relation someRelation = factory.newRelation(new URI("somee-uri.com"), "relatives");
		Link relatives = QueryFactory.ANYCONNECTION(someRelation, bob, alice);

		
		ConstraintMath ageCompare = QueryFactory.MATH_EQUAL(bob.getProperty("age"));
		
		ageCompare.addCalcStep(MathOperation.ADD, alice.getProperty("age"));
		ageCompare.addCalcStep(MathOperation.ADD, QueryFactory.newConstant(5));
		
		Constraint name = QueryFactory.EQUAL(bob.getProperty("name"), QueryFactory.newConstant("bob"));
		
		QueryTree rootQueryTree = QueryFactory.AND(ageCompare, name, relatives);
		
		
//		GraphRelationMember start = new GraphNode("person", new URI("http://someUri.com/armin"), null);
//		GraphRelation rel = new GraphRelation("testRelType", new URI("http://someuri.com"), null);
//		rel.addEntry(start);
//		System.out.println(gson.toJson(rel, GraphRelation.class));
//		gson.fromJson(gson.toJson(rel, GraphRelation.class), GraphRelation.class);

		
		
		Gson gson = new GsonBuilder()
			.registerTypeAdapter(GraphRelationMember.class, new GraphRelationMemberJsonAddapter())
			.create();
	
	
		System.out.println(gson.toJson(bob, Node.class));
		System.out.println(gson.fromJson(gson.toJson(bob, Node.class), Node.class));
		System.out.println("------------------------------------");
		
		System.out.println(gson.toJson(someRelation, Relation.class));
		System.out.println(gson.fromJson(gson.toJson(someRelation, Relation.class), Relation.class));
		System.out.println("------------------------------------");
		
		System.out.println(gson.toJson(someRelation, Relation.class));
		System.out.println(gson.fromJson(gson.toJson(someRelation, Relation.class), Relation.class));
		System.out.println("------------------------------------");
		
	}
	
	
}
